//
//  AttachmentMessageCell.m
//  Estate
//
//  Created by wangdongdong on 16/7/23.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "AttachmentMessageCell.h"
#import "ProcessRecordModel.h"


@interface AttachmentMessageCell ()

// 流程记录模型
@property (nonatomic, strong) ProcessRecordModel *pRecordModel;

@end

@implementation AttachmentMessageCell

-(id)initWithReuseIdentifier:(NSString*)reuseIdentifier withModel:(ProcessRecordModel *)model {
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatSubview:model];
    }
    return self;
}

// 创建子控件
- (void)creatSubview:(ProcessRecordModel *)model {
    // 附件信息
    UILabel *tLbel = [[UILabel alloc] initWithFrame:CGRectMake(16, 10, 0, 0)];
    tLbel.font = [UIFont systemFontOfSize:14];
    tLbel.textColor = UIColorFromRGB(0x009688);
    tLbel.text = @"附件信息";
    [tLbel sizeToFit];
    [self.contentView addSubview:tLbel];
    CGSize tLabelSize = tLbel.frame.size;
    [tLbel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10);
        make.left.offset(16);
        make.width.mas_equalTo(tLabelSize.width);
        make.height.mas_equalTo(tLabelSize.height);
    }];
    
    // 附件施工方说明
    NSArray *descArr = [model.PROCESS_DESC componentsSeparatedByString:@"/"];
    NSMutableArray *arr=[NSMutableArray arrayWithArray:descArr];
    //移除为空的
    if([arr containsObject:@""]){
        [arr removeObject:@""];
    }
    
    NSMutableArray *bArray = [NSMutableArray array];
    if (![model.PROCESS_DESC isEqualToString:@""]) {
        for (int i = 0; i < arr.count; i++) {
            UIButton *explainBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            explainBtn.tag = 1000+i;
            explainBtn.titleLabel.font = [UIFont systemFontOfSize:13];
            [explainBtn setTitleColor:subtitleColor forState:UIControlStateNormal];
            [explainBtn setImage:[UIImage imageNamed:@"sanjiao_1"] forState:UIControlStateNormal];
            [explainBtn setTitle:arr[i] forState:UIControlStateNormal];
            [explainBtn sizeToFit];
            [self.contentView addSubview:explainBtn];
            
            CGFloat w = CGRectGetWidth(explainBtn.frame);
            CGFloat h = CGRectGetHeight(explainBtn.frame);
            [explainBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(tLbel.mas_bottom).offset(5+i*(h+5));
                make.left.offset(16);
                make.width.mas_equalTo(w);
                make.height.mas_equalTo(h);
            }];
            [bArray addObject:explainBtn];
        }
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
